package itsm.isperp.framework.web.formatter;

import itsm.isperp.framework.utils.DateUtils;

import java.beans.PropertyEditorSupport;
import java.sql.Timestamp;
import java.text.ParseException;
import java.util.Date;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.FastDateParser;
import org.apache.xmlbeans.impl.store.Locale;

import com.ibm.icu.util.TimeZone;

/**
 * 
 * 
 * 
 * @author lizx
 * @date 2013-8-28
 * 
 */
public class TimestampEditor extends PropertyEditorSupport {

	@Override
	public void setAsText(String text) throws IllegalArgumentException {

		if (StringUtils.isEmpty(text)) {
			return;
		}
		try { 
			 
			setValue(new Timestamp(DateUtils.parseDateTime(text).getTime()));
		} catch (Exception e) {
			setValue(null);
		}
	}

	@Override
	public String getAsText() throws IllegalArgumentException {
		Object obj = getValue();
		if (obj != null)
			return DateUtils.formatDateTime((Date) obj);
		return null;
	}
}